# 主版本号更新在这里,手动
set(PROJECT_VERSION_MAJOR 1)

# 读取version.h文件
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version.h")
    # 读取 PROJECT_VERSION_PATCH 的值
    file(READ "version.h" VERSION_H_CONTENTS)
    string(REGEX MATCH "PROJECT_VERSION_MINOR \"([0-999]+)\"" _match ${VERSION_H_CONTENTS})
    set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1})
    string(REGEX MATCH "PROJECT_VERSION_PATCH \"([0-999]+)\"" _match ${VERSION_H_CONTENTS})
    set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_1})
    message(STATUS "Read old:${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

    # 判断number是否大于999
    if(${PROJECT_VERSION_PATCH} GREATER 100)
        math(EXPR PROJECT_VERSION_MINOR "${PROJECT_VERSION_MINOR} + 1")
        set(PROJECT_VERSION_PATCH 0)
    else()
        # PROJECT_VERSION_PATCH + 1
        math(EXPR PROJECT_VERSION_PATCH "${PROJECT_VERSION_PATCH} + 1")
    endif()

    set(PROJECT_VERSION  "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
    message(STATUS "new version:${PROJECT_VERSION}")
else ()
    set(PROJECT_VERSION_MINOR 0)
    set(PROJECT_VERSION_PATCH 0)
    set(PROJECT_VERSION  "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
endif ()

# 获取编译日期

string(TIMESTAMP PROJECT_COMPILE_YEAR "%Y" UTC)
string(TIMESTAMP PROJECT_COMPILE_MONTH "%m" UTC)
string(TIMESTAMP PROJECT_COMPILE_DAY "%d" UTC)
string(TIMESTAMP PROJECT_COMPILE_TIME "%Y-%m-%d %H:%M:%S" UTC)

# 生成版本文件
configure_file(version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version.h @ONLY)



